/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "myInit.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for BasicsTask */
osThreadId_t BasicsTaskHandle;
const osThreadAttr_t BasicsTask_attributes = {
  .name = "BasicsTask",
  .stack_size = 512 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for ButtonTask */
osThreadId_t ButtonTaskHandle;
const osThreadAttr_t ButtonTask_attributes = {
  .name = "ButtonTask",
  .stack_size = 256 * 4,
  .priority = (osPriority_t) osPriorityNormal1,
};
/* Definitions for ShootTask */
osThreadId_t ShootTaskHandle;
const osThreadAttr_t ShootTask_attributes = {
  .name = "ShootTask",
  .stack_size = 256 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for DribbleTask */
osThreadId_t DribbleTaskHandle;
const osThreadAttr_t DribbleTask_attributes = {
  .name = "DribbleTask",
  .stack_size = 256 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Can1Task */
osThreadId_t Can1TaskHandle;
const osThreadAttr_t Can1Task_attributes = {
  .name = "Can1Task",
  .stack_size = 256 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for LEDTask */
osThreadId_t LEDTaskHandle;
const osThreadAttr_t LEDTask_attributes = {
  .name = "LEDTask",
  .stack_size = 256 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Button_Buff */
osMessageQueueId_t Button_BuffHandle;
const osMessageQueueAttr_t Button_Buff_attributes = {
  .name = "Button_Buff"
};
/* Definitions for other_CAN1 */
osMessageQueueId_t other_CAN1Handle;
const osMessageQueueAttr_t other_CAN1_attributes = {
  .name = "other_CAN1"
};
/* Definitions for Shoot_CMD */
osMessageQueueId_t Shoot_CMDHandle;
const osMessageQueueAttr_t Shoot_CMD_attributes = {
  .name = "Shoot_CMD"
};
/* Definitions for Dribble_CMD */
osMessageQueueId_t Dribble_CMDHandle;
const osMessageQueueAttr_t Dribble_CMD_attributes = {
  .name = "Dribble_CMD"
};
/* Definitions for Shoot */
osSemaphoreId_t ShootHandle;
const osSemaphoreAttr_t Shoot_attributes = {
  .name = "Shoot"
};
/* Definitions for ShootFinish */
osSemaphoreId_t ShootFinishHandle;
const osSemaphoreAttr_t ShootFinish_attributes = {
  .name = "ShootFinish"
};
/* Definitions for UART_To_RC */
osSemaphoreId_t UART_To_RCHandle;
const osSemaphoreAttr_t UART_To_RC_attributes = {
  .name = "UART_To_RC"
};
/* Definitions for UART_To_PC */
osSemaphoreId_t UART_To_PCHandle;
const osSemaphoreAttr_t UART_To_PC_attributes = {
  .name = "UART_To_PC"
};
/* Definitions for UART_To_Gyro */
osSemaphoreId_t UART_To_GyroHandle;
const osSemaphoreAttr_t UART_To_Gyro_attributes = {
  .name = "UART_To_Gyro"
};
/* Definitions for UART_To_Robot */
osSemaphoreId_t UART_To_RobotHandle;
const osSemaphoreAttr_t UART_To_Robot_attributes = {
  .name = "UART_To_Robot"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void basicsTask(void *argument);
extern void buttonTask(void *argument);
extern void shootTask(void *argument);
extern void dribbleTask(void *argument);
extern void can1Task(void *argument);
extern void ledTask(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* Create the semaphores(s) */
  /* creation of Shoot */
  ShootHandle = osSemaphoreNew(1, 0, &Shoot_attributes);

  /* creation of ShootFinish */
  ShootFinishHandle = osSemaphoreNew(1, 0, &ShootFinish_attributes);

  /* creation of UART_To_RC */
  UART_To_RCHandle = osSemaphoreNew(1, 0, &UART_To_RC_attributes);

  /* creation of UART_To_PC */
  UART_To_PCHandle = osSemaphoreNew(1, 0, &UART_To_PC_attributes);

  /* creation of UART_To_Gyro */
  UART_To_GyroHandle = osSemaphoreNew(1, 0, &UART_To_Gyro_attributes);

  /* creation of UART_To_Robot */
  UART_To_RobotHandle = osSemaphoreNew(1, 0, &UART_To_Robot_attributes);

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* creation of Button_Buff */
  Button_BuffHandle = osMessageQueueNew (1, sizeof(uint8_t), &Button_Buff_attributes);

  /* creation of other_CAN1 */
  other_CAN1Handle = osMessageQueueNew (8, sizeof(MotorToCAN), &other_CAN1_attributes);

  /* creation of Shoot_CMD */
  Shoot_CMDHandle = osMessageQueueNew (1, sizeof(ShootCMD), &Shoot_CMD_attributes);

  /* creation of Dribble_CMD */
  Dribble_CMDHandle = osMessageQueueNew (1, sizeof(enum DribbleMode), &Dribble_CMD_attributes);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of BasicsTask */
  BasicsTaskHandle = osThreadNew(basicsTask, NULL, &BasicsTask_attributes);

  /* creation of ButtonTask */
  ButtonTaskHandle = osThreadNew(buttonTask, NULL, &ButtonTask_attributes);

  /* creation of ShootTask */
  ShootTaskHandle = osThreadNew(shootTask, NULL, &ShootTask_attributes);

  /* creation of DribbleTask */
  DribbleTaskHandle = osThreadNew(dribbleTask, NULL, &DribbleTask_attributes);

  /* creation of Can1Task */
  Can1TaskHandle = osThreadNew(can1Task, NULL, &Can1Task_attributes);

  /* creation of LEDTask */
  LEDTaskHandle = osThreadNew(ledTask, NULL, &LEDTask_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
}

#if 0
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_basicsTask */
/**
  * @brief  Function implementing the BasicsTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_basicsTask */
__weak void basicsTask(void *argument)
{
  /* USER CODE BEGIN basicsTask */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END basicsTask */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
#endif
/* USER CODE END Application */

